import Vue from 'vue'
import Cookies from 'js-cookie'
import ElementUI from 'element-ui';
import './styles/element-variables.scss'
import enLang from 'element-ui/lib/locale/lang/en'
import 'element-ui/lib/theme-chalk/index.css';

import './utils/dialogUtils'

import App from './App.vue'
import router from './router'
import store from './store'
import './assets/css/global.css'
import './icons' // icon
// css
import '@/styles/index.scss' // global css
import './assets/css/global.css'

import './icons' // icon
// import './permission' // permission control
import './utils/error-log' // error log
import * as filters from './filters' // global filters
import {getToken} from "@/utils/auth";

Vue.use(ElementUI, {
  size: Cookies.get('size') || 'medium', // set element-ui default size
  locale: enLang // 如果使用中文，无需设置，请删除
})

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

// login handel:
router.beforeEach((to, from, next) =>{
  if (to.meta.requireAuth){
    store.dispatch('user/getInfo').then(() => {
      console.log('pass')
      next()
    }).catch(()=>{
      console.log('not pass')
      next(
        {
          path: '/login',
          query: {redirect: to.fullPath}
        }
      )
    })
    // if (token){
    //   //
    //   console.log('通过')
    //   //
    //   next()
    // }else{
    //
    // }
  }else{
    next();
  }
})
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
